package com.ymttest.database.mapping.godmember;

import com.ymttest.database.model.godmember.BizType;
import com.ymttest.database.model.godmember.MchMemberConfig;
import com.ymttest.database.model.godmember.Member;
import com.ymttest.database.model.godmember.MemberExample;
import com.ymttest.database.model.godmember.MemberPoints;
import com.ymttest.database.model.godmember.MemberPointsExample;
import com.ymttest.database.model.godmember.PointsEntry;
import com.ymttest.database.model.godmember.PointsEntryExample;
import com.ymttest.database.model.godmember.PointsRule;
import com.ymttest.database.model.godmember.PointsRuleExample;

import java.util.List;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

public interface GodMemberMapper {
	@Update({ "update mchmemberconfig",
			"set  NeedInvitationCode = #{needInvitationCode,jdbcType=BIT}",
			"where ShopId = #{shopId,jdbcType=INTEGER}" })
	int updateMchmemberConfigNeedInvitationCode(MchMemberConfig record);
	
	@Update({ "UPDATE token A INNER JOIN (SELECT Token FROM token WHERE ShopId = 500041475) B",
		"SET A.Token = B.Token",
		"WHERE A.ShopId = #{shopId, jdbcType=INTEGER}" })
	int updateCDFToken(Long ShopId);

	@Select({ "select", "BizType, BizName, CreateTime, UpdateTime",
			"from biztype", "where BizType = #{bizType,jdbcType=INTEGER}" })
	@Results({
			@Result(column = "BizType", property = "bizType", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "BizName", property = "bizName", jdbcType = JdbcType.VARCHAR),
			@Result(column = "CreateTime", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "UpdateTime", property = "updateTime", jdbcType = JdbcType.TIMESTAMP) })
	BizType selectBizTypeByBizType(Integer bizType);

	@Select({ "select * from mchmemberconfig ",
			"where ShopId = #{shopId,jdbcType=INTEGER}" })
	MchMemberConfig selectMchMemberConfigByShopId(Integer shopId);

	@SelectProvider(type = MemberSqlProvider.class, method = "selectByExample")
	List<Member> selectMemberByExample(MemberExample example);

	@SelectProvider(type = MemberPointsSqlProvider.class, method = "selectByExample")
	@Results({
			@Result(column = "MemberId", property = "memberId", jdbcType = JdbcType.VARCHAR, id = true),
			@Result(column = "UserId", property = "userId", jdbcType = JdbcType.INTEGER),
			@Result(column = "ShopId", property = "shopId", jdbcType = JdbcType.INTEGER),
			@Result(column = "AvailablePoints", property = "availablePoints", jdbcType = JdbcType.INTEGER),
			@Result(column = "TotalPoints", property = "totalPoints", jdbcType = JdbcType.INTEGER),
			@Result(column = "OrderNum", property = "orderNum", jdbcType = JdbcType.INTEGER),
			@Result(column = "OrderAmt", property = "orderAmt", jdbcType = JdbcType.DECIMAL),
			@Result(column = "LastMonthOrderAmt", property = "lastMonthOrderAmt", jdbcType = JdbcType.DECIMAL),
			@Result(column = "LastOrderAmt", property = "lastOrderAmt", jdbcType = JdbcType.DECIMAL),
			@Result(column = "LastOrderTime", property = "lastOrderTime", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "LastOrderId", property = "lastOrderId", jdbcType = JdbcType.BIGINT),
			@Result(column = "CreateTime", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "UpdateTime", property = "updateTime", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "RefundAmt", property = "refundAmt", jdbcType = JdbcType.DECIMAL),
			@Result(column = "RefundNum", property = "refundNum", jdbcType = JdbcType.INTEGER) })
	List<MemberPoints> selectMemberPointsByExample(MemberPointsExample example);

	@SelectProvider(type = PointsEntrySqlProvider.class, method = "selectByExample")
	@Results({
			@Result(column = "EntryId", property = "entryId", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "MemberId", property = "memberId", jdbcType = JdbcType.VARCHAR),
			@Result(column = "BizType", property = "bizType", jdbcType = JdbcType.INTEGER),
			@Result(column = "BizId", property = "bizId", jdbcType = JdbcType.VARCHAR),
			@Result(column = "BizAmount", property = "bizAmount", jdbcType = JdbcType.DECIMAL),
			@Result(column = "ChangePoints", property = "changePoints", jdbcType = JdbcType.INTEGER),
			@Result(column = "Points", property = "points", jdbcType = JdbcType.INTEGER),
			@Result(column = "PointsTime", property = "pointsTime", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "Operator", property = "operator", jdbcType = JdbcType.VARCHAR),
			@Result(column = "Remark", property = "remark", jdbcType = JdbcType.VARCHAR),
			@Result(column = "OriginNo", property = "originNo", jdbcType = JdbcType.VARCHAR),
			@Result(column = "CreateTime", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "UpdateTime", property = "updateTime", jdbcType = JdbcType.TIMESTAMP) })
	List<PointsEntry> selectPointsEntryByExample(PointsEntryExample example);

	@SelectProvider(type = PointsRuleSqlProvider.class, method = "selectByExample")
	@Results({
			@Result(column = "RuleId", property = "ruleId", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "ShopId", property = "shopId", jdbcType = JdbcType.INTEGER),
			@Result(column = "BizType", property = "bizType", jdbcType = JdbcType.INTEGER),
			@Result(column = "Threshold", property = "threshold", jdbcType = JdbcType.DECIMAL),
			@Result(column = "Points", property = "points", jdbcType = JdbcType.INTEGER),
			@Result(column = "CreateTime", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "UpdateTime", property = "updateTime", jdbcType = JdbcType.TIMESTAMP) })
	List<PointsRule> selectPointsRuleByExample(PointsRuleExample example);
}